﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Ruandao.MiniFace
{
    public class ScriptBlock : Content
    {
        public string ScriptCode { get; private set; }

        public ScriptBlock(Template template, string scriptCode)
            :base(template)
        {
            this.ScriptCode = scriptCode;
        }

        public override void Render(TemplateContext templateContext, TextWriter writer)
        {
            templateContext.PythonScope.SetVariable("HtmlWriter", writer);
            var source = PythonEngine.GetEngine().CreateScriptSourceFromString(this.ScriptCode);
            source.Execute(templateContext.PythonScope);
            templateContext.PythonScope.RemoveVariable("HtmlWriter");
        }
    }
}
